package psn.zjk.common.algorithm.reverNode;

/**
 * @USER white
 * @DATETIME 2021/1/8 18:41
 */
public class Solution {
    int x = 0;

    public ListNode ReverseList(ListNode head) {
        if (head==null|| head.next == null) {
            return head;
        }
        x++;
        ListNode last = ReverseList(head.next);
        x--;
        head.next.next = head;
        if (x == 0) {
            head.next = null;
        }
        return last;
    }

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1);
        listNode.append().
                append().
                append().
                append().
                append().
                append();
        listNode = new Solution().ReverseList(listNode);
        while (listNode != null) {
            System.out.println(listNode);
            listNode = listNode.next;
        }
    }

}
